package com.bruce.algorithm.leetcode.linklist;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @author luotuan
 * @Description
 * @create 2020-07-18 21:05
 **/
public class LinkListMidNode {
    public ListNode middleNode(ListNode head) {
        if(head==null || head.next==null){
            return head;
        }
        List<ListNode> result = new ArrayList<>();
        while (head!=null){
            result.add(head);
            head = head.next;
        }
        return result.get(result.size()/2);
    }

    public static void main(String[] args) {
        //删除list中的1
        List<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        Iterator<Integer> iterator = list.iterator();
        while (iterator.hasNext()){
            if(iterator.next()==2){
                iterator.remove();
            }
        }
        System.out.println(6/2);
    }
}
